<template>
  <a-card :bordered="false" :class="'cust-erp-sub-tab'">
    <!-- 操作按钮区域 -->
    <div class="table-operator"></div>
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :scroll="{ x: true }"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
      >
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </span>
      </a-table>
    </div>
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getAction } from '@api/manage'

export default {
  name: 'HfSaleOrderConditionDetail',
  mixins: [JeecgListMixin],
  props: {
    mainId: {
      type: String,
      default: '',
      required: false
    }
  },
  watch: {
    mainId: {
      immediate: true,
      handler(val) {
        if (!this.mainId) {
          this.clearList()
        } else {
          this.queryParam['orderId'] = val
          this.loadData(1)
        }
      }
    }
  },
  data() {
    return {
      description: '采购入库明细页面',
      // 表头
      columns: [
        {
          title: '物料代码',
          dataIndex: 'productCode'
        },
        {
          title: '物料名称',
          dataIndex: 'productName'
        },
        {
          title: '规格型号',
          dataIndex: 'sap'
        },
        {
          title: '单位',
          dataIndex: 'unit'
        },
        {
          title: '单箱数',
          dataIndex: 'perNumber'
        },
        {
          title: '箱数',
          dataIndex: 'number'
        },
        {
          title: '应收数量',
          dataIndex: 'orderNumber'
        },
        {
          title: '已收数量',
          dataIndex: 'totalNumber'
        }
      ],
      url: {
        list: '/sale/hfSaleOrder/listHfSaleorderConditionDetailByMainId'
      },
      count: 1
    }
  },
  created() {},
  computed: {},
  methods: {
    clearList() {
      this.dataSource = []
      this.selectedRowKeys = []
      this.ipagination.current = 1
    },
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      let params = this.getQueryParams() //查询条件
      this.loading = true
      getAction(this.url.list, params)
        .then(res => {
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            // this.dataSource = res.result.records || res.result;
            let temp = res.result.records || res.result
            let dataSource = []
            for (let i = 0; i < temp.length; i++) {
              let t = Object.assign(temp[i].hfSaleoutDetail)
              t['orderNumber'] = temp[i].orderNumber
              dataSource.push(t)
            }
            this.dataSource = dataSource
            if (res.result.total) {
              this.ipagination.total = res.result.total
            } else {
              this.ipagination.total = 0
            }
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.loading = false
        })
    }
  }
}
</script>

<style scoped></style>
